<!--
 * @Description: 竣工收尾工作计划业务待办处理页面
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2022-03-14 09:54:20
 * @LastEditTime: 2022-10-25 14:30:47
 * @FilePath: \cscec-pms-admin\src\views\construction\constructionCompleted\pending.vue
-->
<template>
  <base-breadcrumb>
    <title-name title="竣工收尾工作计划" />
    <a-card>
      <p> {{ form.content }} </p>
      <custom-form
        ref="form"
        :is-validate="true"
        :edit-model="''"
        :rules="rules"
        :form="form"
        :form-list="formOption"
      >
        <template slot="fileList">
          <UploadList
            :disabled="resolveInfo"
            business-code="PM43"
            :upload-arrys.sync="form.fileList"
            multiple
            @fileArrysData="handleFileUploaded"
          />
        </template>
      </custom-form>
    </a-card>
    <div class="page-btn-right-top">
      <a-button
        v-if="resolveInfo"
        @click="$close"
      >
        关闭
      </a-button>
      <template v-else>
        <a-button @click="$close">
          取消
        </a-button>
        <a-button
          type="primary"
          class="ml20"
          :loading="submiting"
          @click="handleSubmit"
        >
          处理
        </a-button>
      </template>
    </div>
  </base-breadcrumb>
</template>
<script>
import { formOption } from './model.js'
import UploadList from '@/components/UploadList'
import { implementationManagement } from '@/api/construction/constructionCompleted'
import { finishBusinessTodo } from '@/api/commons.js'
import cloneDeep from 'lodash.clonedeep'
export default {
  name: 'pending' + Date.now(),
  components: {
    UploadList
  },
  data() {
    return {
      // 表单
      form: {
        // 文件列表
        fileList: [],
        content: ''
      },
      // 提交
      submiting: false
    }
  },
  computed: {
    // 是否是业务待办查看处理信息
    resolveInfo: {
      get() {
        return this.$route.query?.resolveInfo === 'true'
      },
      set() {}
    },
    // 表单项
    formOption() {
      return cloneDeep(formOption).filter((el) => {
        // 业务已办查看禁用表单(表单源列表需要深拷贝，每次重新定义则不需要)
        if (this.resolveInfo) el.disabled = true
        if (el.keyName === 'reason') {
          if (this.form.onTimeCompleted === 'false') {
            return el
          }
        } else {
          return el
        }
      })
    },
    // 表单校验
    rules() {
      const obj = {}
      this.formOption.map((item) => {
        if (item.rules) {
          obj[item.keyName] = item.rules
        }
      })
      return obj
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    /**
     * @description: 获取详情
     * @param {void}
     * @return {void}
     */
    getData() {
      implementationManagement.queryCompletionPlanNotifyDetail(this.$route.query.id).then(({ data, code }) => {
        if (code === 200) {
          this.form = data
          this.form.onTimeCompleted = data.onTimeCompleted === 'null' ? undefined : data.onTimeCompleted
        }
      })
    },
    /**
     * @description: 处理
     * @param {void}
     * @return {void}
     */
    handleSubmit() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          this.submiting = true
          const res = await implementationManagement.dealCompletionPlanNotify(this.form)
          if (res.code !== 200) {
            this.submiting = false
            return
          }
          const res1 = await finishBusinessTodo({
            id: this.$route.query.messageId
          })
          if (res1.code !== '0') {
            this.submiting = false
            return
          }
          this.$message.success('成功')
          this.submiting = false
          this.$close()
        }
      })
    },
    /**
     * @description: 文件列表
     * @param {array} list
     * @return {void}
     */
    handleFileUploaded(list) {
      this.form.fileList = [...list]
    }
  }
}
</script>
<style lang="scss">
</style>
